<form action="print.php?code=0017" method="post" target="_blank" onsubmit="return false;" id="form-print">
    <input type="hidden" id="type-view" name="" value='sim'/>
    <label> Origem:
        <select name="origem" id="origem-central" onchange="onChangeOrigem()"
                class="input select-input gray-grad-back smaller-input" >	
            <option value=""> TODAS </option>
            <?php
            include_once CONTROLLERS."loja.php";
            $loja_controller    = new LojaController();
            $all_lojas          = $loja_controller->getAllLojas();
            if ($_SESSION[SESSION_CARGO_FUNC] == CargoModel::COD_DIRETOR ||
                $_SESSION[SESSION_PERFIL_FUNC]== PERFIL_ADMINISTRADOR ) 
            {
                echo "<option value='null'>FORNECEDOR</option>";
                $lojas = $all_lojas;
            } else if($_SESSION[SESSION_CARGO_FUNC] == CargoModel::COD_GERENTE){
                $lojas = array($loja_controller->getLoja($_SESSION[SESSION_LOJA_FUNC]));
            }
            foreach($lojas as $loja){ ?>
                <option value="<?php echo $loja->id; ?>" ><?php echo $loja->sigla;  ?></option>
            <?php } ?>
        </select>
    </label>
    <?php echo hsep(); ?>
    <label> Destino:
        <select name="destino" id="destino-central"
                class="input select-input gray-grad-back smaller-input">	
            <option value=""> TODAS </option>	
            <?php
            foreach($all_lojas as $loja){ ?>
                <option value="<?php echo $loja->id; ?>"><?php echo $loja->sigla;  ?></option>
            <?php } ?>
        </select>
    </label>
    <?php echo hsep(); ?>
    <label> De:
        <input type="date" name="data-limite-inferior" class="input text-input" value="<?php echo date("Y-m-d", strtotime("-1 month"));?>" required/>
    </label>
    <?php echo hsep(); ?>
    <label> Até:
        <input type="date" name="data-limite-superior" class="input text-input" value="<?php echo date("Y-m-d");?>"/>
    </label>
    <span class="h-separator"> &nbsp; </span>
    <label>
        <input type="checkbox" name="resumida" />
        Resumido
    </label>
    <?php echo hsep(); ?>
    <label>
        Situação:
        <?php 
        $props = array('class' => 'input select-input gray-grad-back smaller-input', 'name' => 'status');
        $values = array(' ' => 'TODOS', '1' => 'OK', '0' => 'PENDENTE', '2' => 'PROBLEMAS');
        echo select($values, $props);
        ?>
    </label>
    <p style="text-align: right;margin-top:5px;">
        <button class="btn submit green3-grad-back" name="submit-impressao"> 
            Imprimir <img src="<?php echo GRID_ICONS."impressora.png";?>" style="vertical-align: middle;">
        </button>
        <button class="btn submit green3-grad-back" name="submit-html"> 
            Visualizar <img src="<?php echo GRID_ICONS."documento.png";?>" style="vertical-align: middle;">
        </button>
    </p>
</form>
<script>
$(function(){
    $('#form-print button').click(function(){
        if(this.name.indexOf('impressao') != -1) document.getElementById('type-view').name = 'js';
        else document.getElementById('type-view').name = 'html';
        var form = document.getElementById('form-print');
        form.setAttribute('onsubmit', 'return true;');
        form.onsubmit();
    });
});
function onChangeOrigem(){
    if($("#origem-central").val() == "null"){
        $("#destino-central").val('1');
        document.getElementById("destino-central").disabled = true;
    } else {
        document.getElementById("destino-central").disabled = false;
    }
}
</script>
